package com.xungou.goodtypeproperty.controller;

import com.xungou.goodtypeproperty.pojo.GoodTypeProperty;
import com.xungou.goodtypeproperty.service.IGoodTypePropertyService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/goodTypeProperty")
public class GoodTypePropertyController {
    @Resource
    private IGoodTypePropertyService goodTypePropertyService;

    @RequestMapping("/add")
    @ResponseBody
    public Map<String, Object> add(GoodTypeProperty goodTypeProperty){
        int flag = goodTypePropertyService.insert(goodTypeProperty);
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("flag",flag);
        result.put("id",goodTypeProperty.getId());
        return result;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Map<String, Object> delete(Integer id) {
        int flag = goodTypePropertyService.deleteByPrimaryKey(id);
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("flag",flag);
        return result;
    }

    @RequestMapping("/getAllProperty")
    @ResponseBody
    public List<Map<String, Object>> getAllProperty(@RequestParam Map<String, String> params) {
        List<Map<String, Object>> result = goodTypePropertyService.getAllProperty(params);
        return result;
    }

    @RequestMapping("/getTypePropertyTree")
    @ResponseBody
    public List<Map<String, Object>> getTypeTree(@RequestParam Map<String, String> params) {
        List<Map<String, Object>> result = goodTypePropertyService.getTypePropertyTree(params);
        return result;
    }
}